package org.jsola.hr.common;

import org.jsola.admin.entity.DictItemDO;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.PostType;
import org.jsola.hr.exception.HrException;
import org.jsola.hr.vo.EmpInfoListVO;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

/**
 * @author lyh
 */
public class EmpInfoFieldToString {

    /**
     * 婚姻状况
     */
    private static final String MARITAL_STATUS = "maritalStatus";

    /**
     * 性别
     */
    private static final String GENDER = "gender";

    /**
     * 政治面貌
     */
    private static final String POLITICAL_STATUS = "politicalStatus";

    /**
     * 户口性质
     */
    private static final String REG_TYPE = "regType";

    /**
     * 血型
     */
    private static final String BLOOD_GROUP = "bloodGroup";

    /**
     * 生育状况
     */
    private static final String BIRTH_STATUS = "birthStatus";

    /**
     * 学习形式
     */
    private static final String TEA_METHODS = "teaMethods";

    /**
     * 工作性质
     */
    private static final String POST_TYPE = "postType";

    /**
     * 信息补充
     */
    private static final String IS_IMPROVE =  "isImprove";

    /**
     * 合同状态
     */
    private static final String CONTRACTS_STATUS = "contractsStatus";

    /**
     * 合同类型
     */
    private static final String CONTRACT_TYPE = "contractType";

    /**
     * 是否实名
     */
    private static final String VERIFIED = "verified";

    private static final String FORMAL_TYPE = "formalType";

    public static String fieldToString(Field field, EmpInfoListVO empInfoListVO, Map<String, String> postTypeMap){
        //属性名
        String name = field.getName();
        //属性值定义
        Object value;
        //返回值
        String result;
        try {
            value = field.get(empInfoListVO);
        } catch (IllegalAccessException e) {
            throw new HrException("无法访问属性");
        }
        //如果属性是婚姻状况
        if(MARITAL_STATUS.equals(name)){
            switch (value.toString()){
                case "1": result = "已婚"; break;
                case "2": result = "未婚"; break;
                case "3": result = "离异"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是性别
        if(GENDER.equals(name)){
            switch (value.toString()){
                case "1": result = "男"; break;
                case "2": result = "女"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是政治面貌
        if(POLITICAL_STATUS.equals(name)){
            switch (value.toString()){
                case "1": result = "中共党员"; break;
                case "2": result = "共青团员"; break;
                case "3": result = "普通居民/群众"; break;
                case "4": result = "其他"; break;
                case "5": result = "积极分子"; break;
                case "6": result = "预备党员"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是血型
        if(BLOOD_GROUP.equals(name)){
            switch (value.toString()){
                case "1": result = "A"; break;
                case "2": result = "B"; break;
                case "3": result = "AB"; break;
                case "4": result = "O"; break;
                case "5": result = "其他"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是户口性质
        if(REG_TYPE.equals(name)){
            switch (value.toString()){
                case "1": result = "城镇户口"; break;
                case "2": result = "农村户口"; break;
                case "3": result = "居民户口"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是生育状况
        if(BIRTH_STATUS.equals(name)){
            switch (value.toString()){
                case "1": result = "已育"; break;
                case "2": result = "未生育"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是学习形式
        if(TEA_METHODS.equals(name)){
            switch (value.toString()){
                case "1": result = "全日制"; break;
                case "2": result = "成人教育"; break;
                case "3": result = "远程教育"; break;
                case "4": result = "自学考试"; break;
                case "5": result = "其他非全日制"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是工作性质
        if (POST_TYPE.equals(name)) {
//            Integer val = SafeKit.getInteger(value);
//            if (val == null) {
//                return "";
//            }
//            postTypeMap.get(value);
//            PostType postType = PostType.find(val);
//            if (postType != null) {
//                return postType.getDesc();
//            }
            return postTypeMap.get(String.valueOf(value));
        }
        //如果属性是信息补充
        if(IS_IMPROVE.equals(name)){
            switch (value.toString()){
                case "true": result = "已完善"; break;
                case "false": result = "未完善"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是实名认证
        if(VERIFIED.equals(name)){
            switch (value.toString()){
                case "true": result = "已认证"; break;
                case "false": result = "未认证"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是合同状态
        if(CONTRACTS_STATUS.equals(name)){
            switch (value.toString()){
                case "0": result = "合同未发起"; break;
                case "1": result = "待员工签署"; break;
                case "2": result = "待公司签署"; break;
                case "3": result = "签署完成"; break;
                case "-1": result = "合同过期未签署"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是合同类型
        if(CONTRACT_TYPE.equals(name)){
            switch (value.toString()){
                case "laborContractLimit": result = "固定期限劳动合同"; break;
                case "laborContractUnlimit": result = "无固定期限劳动合同"; break;
                case "laborContractJobs": result = "以完成一定工作任务为期限的劳动合同"; break;
                case "internAccords": result = "实习协议"; break;
                case "laborContract": result = "劳务合同"; break;
                case "reemployAccords": result = "返聘协议"; break;
                case "laborContractDispatch": result = "劳务派遣合同"; break;
                case "borrowedContract": result = "借调合同"; break;
                case "engagementLetter": result = "约定书"; break;
                case "other": result = "其它"; break;
                default: result = "";
            }
            return result;
        }
        //如果属性是员工类型
        if(FORMAL_TYPE.equals(name)){
            switch (value.toString()){
                case "0": result = "其他"; break;
                case "1": result = "试用"; break;
                case "2": result = "正式"; break;
                default: result = "";
            }
            return result;
        }
        return value.toString();
    }
}
